package cn.kgm.bitmap.hashIfElse;

import java.util.HashMap;
import java.util.function.Function;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2023-9-18 15:14
 * @Description: cn.kgm.bitmap.hashIfElse.HashIfElseTest
 */

public class HashIfElseTest {
    static HashMap<String, Function<String, String>> dataMappings = new HashMap<String, Function<String, String>>() {
        {
            put("0", (String param) -> {
                return param;
            });
            put("1", (String param) -> {
                return param;
            });
            put("2", (String param) -> {
                return param;
            });
            put("3", (String param) -> {
                return deal(param);
            });
            put("4", (String param) -> {
                return deal(param);
            });
        }
    };
    static Function<String, String> defaultMapping = new Function<String, String>() {
        @Override
        public String apply(String s) {
            return "default";
        }
    };

    public static void main(String[] args) {
        String aResult = dataMappings.getOrDefault("0", defaultMapping).apply("a-result");
        System.out.println(aResult);
        String bResult = dataMappings.get("1").apply("b-result");
        System.out.println(bResult);
        String cResult = dataMappings.getOrDefault("3", defaultMapping).apply("c-result");
        System.out.println(cResult);
        String defaultResult = dataMappings.getOrDefault("100", defaultMapping).apply("default-result");
        System.out.println(defaultResult);
    }

    static String deal(String param) {
        return "after deal:" + param;
    }
}
